package com.sabeot.library.hibernate.dto;

import java.util.Calendar;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
import javax.persistence.Table;


@Entity
@Table(name="app_users",schema="library")
public class User extends BasicDTO{

	@Column(name="login", unique=true, nullable=false)
	private String login;
	
	@Column(name="password", nullable=false)
	private String password;
	
	@Column(name="is_active", nullable=false)
	private Boolean active;
	

	@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
	private UserDetails userDetails;
	
	/*
	 * Constructors
	 */
	public User(){
	}
	
	public User(String login, String password){
		Date currentDate = Calendar.getInstance().getTime();
		this.login = login;
		this.password = password;
		this.active = false;
		this.modifyDate = currentDate;
		this.createDate = currentDate;
	}
	
	public User(String login, String password, Boolean active){
		Date currentDate = Calendar.getInstance().getTime();
		this.login = login;
		this.password = password;
		this.active = active;
		this.modifyDate = currentDate;
		this.createDate = currentDate;
	}
	
	public User(String login, String password, Boolean active, UserDetails userDetails){
		Date currentDate = Calendar.getInstance().getTime();
		this.login = login;
		this.password = password;
		this.active = active;
		this.userDetails = userDetails;
		this.modifyDate = currentDate;
		this.createDate = currentDate;
	}
	
	/*
	 * Getters and Setters
	 */

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	public UserDetails getUserDetails() {
		return userDetails;
	}

	public void setUserDetails(UserDetails userDetails) {
		this.userDetails = userDetails;
	}
	
	
}
